<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <router-link to="/register">注册</router-link>
    <router-link to="/login">登录</router-link>

    <router-view></router-view>
  </div>
  <script src="./vue.js"></script>
  <script src="./vue-router.js"></script>

  <script>
    const Register = {
      template: '<div>注册了11111111111111</div>'
    }
    const One = {
      template: '<div>one111111oneoenoen1</div>'
    }
    const Two = {
      template: '<div>222222222twotwo1<button @click="backTo">返回</button></div>',
      methods: {
        backTo() {
          this.$router.go(-1)
        }
      }
    }
    const Login = {
      template: `<div>
        <h2>loginLOGIN11111111111111</h2>

        <router-link to="/login/one">一</router-link>
        <router-link to="/login/two">二</router-link>
        <button @click="goTwo">跳到 二</button>

        <router-view></router-view>
      </div>`,
      methods: {
        goTwo() {
          this.$router.push('/login/two')
        }
      }
    }

    const test = new VueRouter({
      routes: [
        { path: '/', redirect: '/login' },
        { path: '/register', component: Register },
        { 
          path: '/login', 
          component: Login,
          children: [
            { path: '/login/one', component: One},
            { path: '/login/two', component: Two}
          ]
        }
      ]
    })

    new Vue({
      el: '#app',
      router: test
    })
  </script>
</body>
</html>